<%@ page import = "jp.ac.utokyo.pinyomi.*" %>
<%@ page contentType="text/html; charset=UTF-8" %>

<jsp:useBean id="results" class="jp.ac.utokyo.pinyomi.Results" scope="session"/>
<%
	results.processRequest(request, pageContext);
	String cntx = request.getContextPath();
	String thispage = request.getRequestURI();
%>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<link rel="stylesheet" type="text/css" href="css/changelists.css">
<title>Pinyomi</title>

<script type="text/javascript">
function init() {
	document.lookup.query.focus();
}

function submit(){
	if (document.lookup.query.value=="") {
		alert("Input a query please.");
		return false;
	}
	return true;
}

</script>

</head>

<body class="change-list" onload="init()"> 
  <div id="container">
    <div id="header">
      <div id="branding">
        <h1 id="site-name">Pinyomi Dictionary Lookup</h1>
      </div>
      <div id="user-tools">
        <a href="<%=cntx%>/searchjp.jsp">Japanese lookup</a> /
        <a href="<%=cntx%>/searchch.jsp">Chinese lookup</a>
      </div>
    </div>
    
    <div id="content" class="flex">
      
<h1>Japanese dictionary</h1>
<div id="content-main">
  <form name="lookup" action="<%=thispage%>" method="post" onsubmit="submit()">
<%	String method = results.getMethod();
	method = (method == null || method.equals(""))? "index" : method;
	String isexact = results.isExactMatch() ? "checked" : "";
%>
	<input name="method" value="<%=method %>" type="hidden">
    <input name="query" value="<%=results.getQuery()%>" type="text">
    <input class="default" name="action" value="Search" type="submit">
    <input name="action" value="Clear" type="submit">
    <input name="dicttype" value="jp" type="hidden">
    &nbsp;&nbsp;&nbsp;&nbsp;<input name="exact" type="checkbox" <%=isexact%>> Exact match
    
  </form>
  <h2>Results</h2>
  <p><%=results.getResultSetSize()%> result(s) in <%=results.getTime()%> micro-second(s).</p>
  <table border="1">
    <thead>
      <tr>
        <th>Word</th>
        <th>Reading</th>
        <th>Meaning</th>
        <th>Chinese Meaning</th>
        <th>Score</th>
      </tr>
    </thead>
    <tbody>
<%String styleClass = "row1";
  for (ResultRecord record : results.getResultSet() ) {%>
      <tr class="<%=styleClass %>">
        <td><%=record.getTranslation() %></td>
        <td><%=record.getReading() %></td>
        <td><%=record.getMeaning() %></td>
        <td><A href="http://www.excite.co.jp/dictionary/japanese_chinese/?search=<%=record.getTranslation()%>" target="_blank" >Chinese</A></td>
        <td><%=record.getPinyomiScore(2) %></td>
      </tr>
<%    styleClass = styleClass.equals("row1") ? "row2" : "row1" ;
  }
%>
    </tbody>
  </table>
  <br>
</div>

    </div>
  </div>
</body>
</html>
